﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StringFun
{
    class Program
    {
        static void Main(string[] args)
        {
            String procText = String.Empty;
            procText = EnterText();
            procText = RemoveComment(procText);
            PrintPopularWord(procText);
            Console.WriteLine("{0} - это если без комментариев", procText);
            PrintABCwords(procText);
            Console.ReadKey();
        }
        public static String EnterText()
        {
            String result = String.Empty;
            Console.WriteLine();
            result = Console.ReadLine();
            return result;
        }
        public static String RemoveComment(String incomingText)
        {
            String result = String.Empty;
            String[] separators = new String[] { "/*", "*/" };
            String[] resultArr = incomingText.Split(separators, StringSplitOptions.RemoveEmptyEntries);
            StringBuilder proc = new StringBuilder(incomingText.Length);
            if (resultArr.Length > 1)
            {
                for (int i = 0; i < resultArr.Length; i = i + 2)
                {
                    proc.Append(resultArr[i]);
                }
                result = proc.ToString();
            }
            else
            {
                return incomingText;
            }
            return result;
        }
        public static void PrintPopularWord(String incomingText)
        {
            Char[] separators = new Char[] { ' ', ',' };
            String[] resultArr = incomingText.Split(separators, StringSplitOptions.RemoveEmptyEntries);
            Int32[] wordsCount = new Int32[resultArr.Length];
            Int32 maxIndex = 0;
            if (resultArr.Length < 2) return;
            for (Int32 i = 0; i < resultArr.Length; i++)
            {
                for (Int32 j = 0; j < resultArr.Length; j++)
                {
                    if (resultArr[i] == resultArr[j])
                    {
                        wordsCount[i]++;
                    }
                }
                if (wordsCount[i] > maxIndex)
                {
                    maxIndex = i;
                }
            }
            Console.WriteLine("{0} - подозрительно часто встречается", resultArr[maxIndex]);
        }
        public static void PrintABCwords(String incomingText)
        {
            Char[] separators = new Char[] { ' ', ',' };
            String[] procArr = incomingText.Split(separators, StringSplitOptions.RemoveEmptyEntries);
            StringBuilder result = new StringBuilder(procArr.Length);
            for (Int32 i = 0; i < procArr.Length; i++)
            {
                if (IsABCword(procArr[i].ToLower()))
                {
                    result.Append(procArr[i]);
                }
            }
            Console.WriteLine("{0} - слова с алф. последовательностью букв.",result.ToString());
        }
        public static bool IsABCword(String incomingText)
        {
            Boolean alf = false;
            if (incomingText.Length<2) return true;
            for (Int32 i = 0; i < incomingText.Length-1; i++)
            {
                if (incomingText[i] < incomingText[i + 1])
                {
                    alf = true;
                }
                else return false;
            }
            return alf;
        }
    }
}
